package com.probox.modules.controller.order;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.order.OrderShipAuto;
import com.probox.common.entity.service.order.IOrderShipAutoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 自动收货时间Controller
 *
 * @author hds
 * @date 2021-05-28
 */
@RestController
@RequestMapping("/order/auto")
public class OrderShipAutoController extends BaseController {
    @Autowired
    private IOrderShipAutoService orderShipAutoService;

    /**
     * 查询自动收货时间列表
     */
    @PreAuthorize(hasPermi = "order:auto:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderShipAuto orderShipAuto) {
        startPage();
        List<OrderShipAuto> list = orderShipAutoService.queryList(orderShipAuto);
        return getDataTable(list);
    }

    /**
     * 导出自动收货时间列表
     */
    @PreAuthorize(hasPermi = "order:auto:export")
    @Log(title = "自动收货时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderShipAuto orderShipAuto) throws IOException {
        List<OrderShipAuto> list = orderShipAutoService.queryList(orderShipAuto);
        ExcelUtil<OrderShipAuto> util = new ExcelUtil<OrderShipAuto>(OrderShipAuto.class);
        util.exportExcel(response, list, "自动收货时间数据");
    }

    /**
     * 获取自动收货时间详细信息
     */
    @PreAuthorize(hasPermi = "order:auto:query")
    @GetMapping(value = "/{autoUid}")
    public AjaxResult getInfo(@PathVariable("autoUid") Integer autoUid) {
        return AjaxResult.success(orderShipAutoService.selectOrderShipAutoById(autoUid));
    }

    /**
     * 新增自动收货时间
     */
    @PreAuthorize(hasPermi = "order:auto:add")
    @Log(title = "自动收货时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderShipAuto orderShipAuto) {
        return toAjax(orderShipAutoService.insertOrderShipAuto(orderShipAuto));
    }

    /**
     * 修改自动收货时间
     */
    @PreAuthorize(hasPermi = "order:auto:edit")
    @Log(title = "自动收货时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderShipAuto orderShipAuto) {
        return toAjax(orderShipAutoService.updateOrderShipAuto(orderShipAuto));
    }

    /**
     * 删除自动收货时间
     */
    @PreAuthorize(hasPermi = "order:auto:remove")
    @Log(title = "自动收货时间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{autoUids}")
    public AjaxResult remove(@PathVariable Integer[] autoUids) {
        return toAjax(orderShipAutoService.deleteOrderShipAutoByIds(autoUids));
    }
}
